﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AgnisEbmtTranslator;
using AgnisDAL;

namespace TestApplication
{
    public class CInitialGenerationProcess
    {
        private String currentEbmtDbConnectionString;
        private String currentMappingInfoConnectionString;
        private String currentAgnisStagingConnectionString;
        private int _ebmt_Id, _ebmt_Idaa, _formNumber;
        private decimal _form_Version;
        DateTime _dateOfTransplant;
        TranslatorProcess.AgnisForm2450DuePeriods _DuePeriod;
        private int formPublicId;
        private string version = "1,0";
        private int visit_id = -2;

        public int Ebmt_Id
        {
            get { return _ebmt_Id; }
            set { _ebmt_Id = value; }
        }
        public int Ebmt_Idaa
        {
            get { return _ebmt_Idaa; }
            set { _ebmt_Idaa = value; }
        }
        public int Form_Number
        {
            get { return _formNumber; }
            set { _formNumber = value; }
        }
        //public int Visit_Id
        //{
        //    get { return _visitId; }
        //    set { _visitId = value; }
        //}
        //public int FormPublicId
        //{
        //    get { return _formPublicId; }
        //    set { _formPublicId = value; }
        //}
        public decimal FormVersion
        {
            get { return _form_Version; }
            set { _form_Version = value; }
        }
        public TranslatorProcess.AgnisForm2450DuePeriods FormDuePeriod
        {
            get { return _DuePeriod; }
            set { _DuePeriod = value; }
        }


        public void SetCurrentEbmtDbConnectionString(String cString)
        {
            currentEbmtDbConnectionString = cString;
        }

        public void SetCurrentMappingInfoConnectionString(String cString)
        {
            currentMappingInfoConnectionString = cString;
        }
        public void SetCurrentAgnisStagingConnectionString(string cString)
        {
            currentAgnisStagingConnectionString = cString;
        }

        public CInitialGenerationProcess(int ebmt_id, int ebmt_idaa, DateTime dateOfTransplant/*, decimal formVersion*/, TranslatorProcess.AgnisForm2450DuePeriods formDuePeriod)
        {
            _ebmt_Id = ebmt_id;
            _ebmt_Idaa = ebmt_idaa;
            _dateOfTransplant = dateOfTransplant;

            //_form_Version = formVersion;
            _DuePeriod = formDuePeriod;
        }

        private void SetFormPublicId(int _paperFormNumber)
        {
            switch (_paperFormNumber)
            {
                case 2400:
                    formPublicId = 3002012;
                    version = "2,0";
                    break;
                case 2450:
                    formPublicId = 2898108;
                    visit_id = -1; // 100 days
                    break;
                case 2900:
                    formPublicId = 2892254;
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// Translate and Load Form
        /// </summary>
        public void GenerateNewFormRevision()
        {
            string empty_instance_Id = "";
            int iModPublicId = 0; //To DO
            //temporary form version for test
            //decimal tmpVersion = decimal.Parse("1.0", System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
            SetFormPublicId(Form_Number);
            TranslatorProcess tProcess1 = new TranslatorProcess(currentEbmtDbConnectionString, currentMappingInfoConnectionString);
            AgnisDAL.ServiceAgnis.FormRevision myNewGeneratedFormRevision;
            //actually, "Due period" value is forced at '100Days' 
            myNewGeneratedFormRevision = tProcess1.GenerateAgnisFormForPatient(_ebmt_Id, _ebmt_Idaa, _dateOfTransplant, _formNumber, formPublicId, Convert.ToDecimal(version), TranslatorProcess.AgnisForm2450DuePeriods.HundredDays, empty_instance_Id);


            AgnisDAL.cAgnisDAL.SetConnectionString(currentAgnisStagingConnectionString);
            // loading form process
            AgnisDAL.cAgnisDAL.SendFormRevisionToDB(myNewGeneratedFormRevision, _formNumber, formPublicId, visit_id, _ebmt_Id, _ebmt_Idaa, _dateOfTransplant, 0, empty_instance_Id, iModPublicId, decimal.Parse(version, System.Globalization.CultureInfo.CreateSpecificCulture("en-US")),0);



        }


    }
}